#include <QCoreApplication>
#include <iostream>
using namespace std;

class Persion98{
public :
    static int age ;
};
// 静态属性必须在类外初始化
int Persion98::age =99;
int main(int argc, char *argv[])
{
    Persion98::age  =88; //  更直接，推荐使用；
    Persion98 p1;
    cout << p1.age;
    p1.age = 9 ;
    Persion98 p2;
    cout << p2.age;
    cout << "OK";
    return 0;
}


class Person99{
public:
    Person99(int a, int b, int c):m_A(a),m_B(c),m_C(c){

    }
public  :
    int m_A;
    int m_B;
    int m_C;
};


int main8(int argc, char *argv[])
{
    Person99 p(1,2,3);
    cout << p.m_A << "\t" <<p.m_B <<endl;
    return 0;
}



class Book99{
public  :
    Book99(int p ){ //
        price = p;
    }

    int price = 10;

};

int main6(int argc, char *argv[])
{
    Book99  b(99);
    b.price =9;
    Book99 b2(b);
    cout << b2.price;


    return 0;
}



class Book{
public   :
    // 所有的属性值默认都是零
    int price ;
    string title;
    char  c;  // 0  \0
    bool  b; //  0 ---> false;
    //  编译器默认为类提供构造器


public :
    Book(){
        // 被默认调用，不需要显示调用
        cout << "Book" <<endl;
        // 所有的属性默认为零
    }
    // 构造器重载；
    Book(int p){
        price = p ;
    }
    Book(int p, string t){
        price = p ;
        title = t;
    }
    Book(const Book & b  ){
        price =  b.price;
        title = b.title;
    }
    ~Book(){
       cout <<  "~~~~~~~~" << endl;
    }
    void showPrice(){
        cout <<  price << endl;
        cout <<  title << endl;

    }

};



int main5(int argc, char *argv[])
{
    Book *b1= new Book(1);
    b1->showPrice();
    Book *b2= new Book(2);
    b2 =  b1; //  两个指针的赋值
    b2->showPrice();



    // Book b(9,"c++");
    // Book b1(b);
    // Book b2;
    // b2 = b; // 对象的克隆拷贝,
    // // b1.showPrice();
    // // b2.showPrice();
    // b.price  = 99;
    // b2.price =98;
    // b.showPrice();
    // b2.showPrice();
    // Book b(9);
    // Book *b1 = new Book(99);
    // b.showPrice();
    // b1->showPrice();// (*b1).showPrice();  通过指针访问对象的成员
    // delete b1;
    return 0;
}



/**
 * 最简单的复制粘贴
 * 继承解决相同代码不写两遍的问题，子类拥有父类 的一切
 */
class Animal{
public:
    int pubi =1;
    void sleep(){
        cout << "sleeping...." <<endl;
    }
    void showPrii(){
        cout <<  prii <<endl;
    }
private :
    int prii =10;
};



class Cat96: public   Animal{
};


class Dog96 : public  Animal{
};


int main3(int argc, char *argv[])
{
    Cat96 c1;
    c1.pubi =3;
    c1.showPrii();

    // c1.sleep();
    // Dog96 d ;
    // d.sleep();
    return 0;
}


/**
 * 细节隐藏
 * 隐私级别：访问修饰符
 */
class Dog99{
public:
    int pub_age =1;
protected:
    int pro_age =2;
private:
    int priv_Age =3;
    int def_age =4;
public:
    void pub_func(){
        cout << "pub_age : " << pub_age <<endl;
        cout << "pro_age : " << pro_age <<endl;
        cout << "priv_Age : " << priv_Age <<endl;
        cout << "def_age : " << def_age <<endl;
        Dog99  d99;
        d99.priv_Age =12;
        d99.def_age = 13;
    }
protected:
    void prot_func(){
        cout << "pub_age : " << pub_age <<endl;
        cout << "pro_age : " << pro_age <<endl;
        cout << "priv_Age : " << priv_Age <<endl;
        cout << "def_age : " << def_age <<endl;
    }
private:
    void priv_func(){
        cout << "pub_age : " << pub_age <<endl;
        cout << "pro_age : " << pro_age <<endl;
        cout << "priv_Age : " << priv_Age <<endl;
        cout << "def_age : " << def_age <<endl;
    }
    void defa_func(){
        cout << "pub_age : " << pub_age <<endl;
        cout << "pro_age : " << pro_age <<endl;
        cout << "priv_Age : " << priv_Age <<endl;
        cout << "def_age : " << def_age <<endl;
    }

};

class Dog98 :public Dog99{
public:
    void fun1(){
        pub_age =15;
        pro_age =16;
        // priv_Age =17;
        // def_age =18;
        Dog99 d99;
        Dog98 d98;

    }
};

class Dog97{
public:
    void fun1(){
      //  pub_age =15;
      //  pro_age =16;
        // priv_Age =17;
        // def_age =18;
        Dog99 d99;
        Dog98 d98;

    }
};

int main2(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    return a.exec();
}



// 封装实现细节隐藏，但是需要提供公共的访问接口实现数据的通信
class Dog{  //  封装的语法：  {  }
    int age =3;
public:
    int  getAge(){
        return age;
    }
    void setAge(int a){
        if(a >  0)
            age = a;
        else {
            cout << "Age error" << endl;
        }
    }
};
typedef struct xxxx
{
    int age;
}Cat1;
// 类和结构体的唯一区别：成员默认访问修饰符不同，为了对象属性数据的安全性，我们总是采用类而不是结构体
int main1(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    Cat1 c1;
    c1.age = -20;
    cout << "OK"<< endl;
    Dog d1 ; //封装：对象之间是独立的
    Dog d2 ;
    d2.setAge(-2);
    cout << d2.getAge()<< endl;
    return a.exec();
}

